/*
 * Hyuga: A Density-Grid Stream Clustering Platform.
 * Copyright (C) 2014 PUC-Rio/Laboratory for Advanced Collaboration
 *
 * Hyuga is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Hyuga is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Hyuga.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.pucrio.inf.lac.konoha.hyuga.events;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import br.pucrio.inf.lac.konoha.hyuga.common.CSVUtil;
import br.pucrio.inf.lac.konoha.hyuga.events.csv.CSVLocationUpdateEvent;

/**
 * Represent the basic location update event. This event is the entry point of the Hyuga algorithm. It contains the
 * mobile nodes position (latitude, longitude), id, icon and operation of the location update.
 * 
 * @author Marcos Roriz <mroriz@inf.puc-rio.br>
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class LocationUpdateEvent extends CEPEvent {
	private double	latitude;
	private double	longitude;
	private UUID	uuid;
	private String  originalID;
	private String	icon;
	private String	operation;

	// Cell Index (Context Partition) 
	private int	x; // longitude index
	private int	y; // latitude  index
	
    // Cell Subdivision
    protected int hsweep; // Horizontal Sweep Index
    protected int vsweep; // Vertical   Sweep Index
    
    // Have been removed?
    protected boolean valid;
    
	// Default Empty Constructor for JSON JavaBean
	public LocationUpdateEvent() {
		this(0, 0);
	}
	
	// Basic Constructor
	public LocationUpdateEvent(double lat, double lng) {
		this(UUID.randomUUID(), lat, lng);
	}
	
	// Basic Constructor with ID
    public LocationUpdateEvent(UUID id, double lat, double lng) {
        this(id, lat, lng, "default.png", "location_update");
    }

	// Full Constructor
	public LocationUpdateEvent(UUID id, double lat, double lng, String icon, String operation) {
	    // Event Info
		this.operation = operation;
		this.latitude  = lat;
		this.longitude = lng;
		this.uuid      = id;
		this.icon      = icon;
		this.type      = TYPE.LOCATIONUPDATE;
		
		// Mapped Cell Info (empty at first)
		this.x = 0;
		this.y = 0;
		this.hsweep = 0;
		this.vsweep = 0;
		
		// Boolean Valid
		this.valid = true;
		
		// Topic
		this.outputTopic = "LocationUpdateEvent";
	}
	
	// CSV Constructor
	public LocationUpdateEvent(CSVLocationUpdateEvent csvLU) {
	    this(CSVUtil.getUUID(csvLU.getUuid()), csvLU.getLatitude(), csvLU.getLongitude());
	    this.originalID = csvLU.getUuid();
	}

	@Override
	public String toString() {
	    return "[ Location Update | " + latitude + " | " + longitude + " | " + x + " | " + y + " | " + uuid + "]";   
	}
	
	//////////////////////////////////////////////////////////////////////////
	// Get and Sets
	//////////////////////////////////////////////////////////////////////////
	public String getOriginalID() {
        return originalID;
    }
	
	public void setOriginalID(String originalID) {
        this.originalID = originalID;
    }
	
	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public UUID getUuid() {
		return uuid;
	}

	public void setUuid(UUID uuid) {
		this.uuid = uuid;
	}
	
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	public int getX() {
		return x;
	}

    public void setX(int x) {
        this.x = x;
    }
    
    public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
    }

	public int getHsweep() {
        return hsweep;
    }
	
	public void setHsweep(int hsweep) {
        this.hsweep = hsweep;
    }
	
	public int getVsweep() {
        return vsweep;
    }
	
	public void setVsweep(int vsweep) {
        this.vsweep = vsweep;
    }
	
	public boolean isValid() {
        return valid;
    }
	
	public void setValid(boolean valid) {
        this.valid = valid;
    }

}
